﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ESHOP.Domain;

namespace ESHOP.DAO
{
    public class UserAdminDao:BaseDAO
    {
        public USER_ADMIN Get(string ma)
        {
            return _db.USER_ADMINs.SingleOrDefault(p => p.MANV.Equals(ma));
        }
        public USER_ADMIN Get(string User,String Pass)
        {
            return _db.USER_ADMINs.SingleOrDefault(p =>p.USERNAME.Equals(User)&& p.PASS.Equals(Pass));
        }
        public List<USER_ADMIN> GetList()
        {
            return _db.USER_ADMINs.ToList();
        }


        public List<USER_ADMIN> GetList(int fromIndex, int toIndex)
        {
            return GetList().Skip(fromIndex).Take(toIndex - fromIndex).ToList();
        }

        public int Count()
        {
            return _db.USER_ADMINs.Count();
        }

        public int Insert(USER_ADMIN objUi)
        {

            try
            {

                _db.Connection.Open();

                _db.USER_ADMINs.InsertOnSubmit(objUi);
                _db.SubmitChanges();

                // commit

                // success message
                return 1;
            }
            catch (Exception ex)
            {
                // rollback transaction

                return 0;
            }
            return 1;
        }
    }
}
